package com.atguigu.day09.test.test;

import java.awt.*;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/9 16:50
 * @注释 - 属性：a,b,c分别代表三角形的三边，私有化
 *      - 提供get/set
 *      - 提供有参构造，public Triangle(double a, double b, double c)，并验证a,b,c的值是否可以构成三角形，如果可以构成三角形再为a,b,c的属性赋值
 *      - 重写area()和perimeter方法，
 *      - 重写toString方法，返回“边长：xx,xx,xx，面积：xxx，周长：xxx”
 */
public class Triangle extends Graphic {
    private double a;
    private double b;
    private double c;


    @Override
    public double area() {
        double p = (a + b + c) / 2;
        return Math.sqrt(p * (p - a) * (p - b) * (p - c));
    }

    @Override
    public double perimeter() {
        return a + b + c;
    }

    @Override
    public String toString() {
        return "三角形的三条边分别为: " + a + ", " + b + ", " + c +
                ", 面积为: " + area() + ", 周长为: " + perimeter();
    }

    public Triangle(double a, double b, double c) {
        if(a > 0 && b > 0 && c > 0 && a + b > c && b + c > a && a + c > b){
            this.a = a;
            this.b = b;
            this.c = c;
        }else{
            System.out.println("您输入的边长有误");
        }

    }

    public Triangle() {
    }

    public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    public double getB() {
        return b;
    }

    public void setB(double b) {
        this.b = b;
    }

    public double getC() {
        return c;
    }

    public void setC(double c) {
        this.c = c;
    }
}
